//
//  ViewController.m
//  UI14_UICollectionViewText(半塘晒单)
//
//  Created by Hanlingyu on 16/8/2.
//  Copyright © 2016年 ltq. All rights reserved.
//

#import "ViewController.h"
#import "ClassesCollectionViewCell.h"
#import "ClassCollectionReusableView.h"
#import "HotCollectionViewCell.h"
#define kCollectionViewReuse @"reuse"
#define kCollectionViewReusable @"footerReuse"
@interface ViewController ()
<
    UICollectionViewDataSource,
    UICollectionViewDelegate,
    UICollectionViewDelegateFlowLayout
>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];

    CGFloat itemWidth = (CGRectGetWidth(self.view.bounds) - 10) / 3;
    layout.itemSize = CGSizeMake(itemWidth, itemWidth);
    layout.minimumLineSpacing = 5;
    layout.minimumInteritemSpacing = 5;

    layout.sectionInset = UIEdgeInsetsMake(2.5f, 0, 2.5f, 0);
    layout.headerReferenceSize = CGSizeMake(0, 400);
    
    layout.scrollDirection = UICollectionViewScrollDirectionVertical;
    UICollectionView *itemizeCollectionView = [[UICollectionView alloc] initWithFrame: self.view.frame collectionViewLayout:layout];
    itemizeCollectionView.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:itemizeCollectionView];
    itemizeCollectionView.dataSource = self;
    itemizeCollectionView.delegate = self;
    
    [itemizeCollectionView registerClass:[HotCollectionViewCell class] forCellWithReuseIdentifier:kCollectionViewReuse];
    
    [itemizeCollectionView registerClass:[ClassCollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusable];
    
    
    
}

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    
    return 1;
}

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 21;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    ClassesCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kCollectionViewReuse forIndexPath:indexPath];
    cell.backgroundColor = [UIColor redColor];
    return cell;
    
    
}

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {
    
    ClassCollectionReusableView *reusableView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:kCollectionViewReusable forIndexPath:indexPath];
    reusableView.backgroundColor = [UIColor redColor];
    return reusableView;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
